Component({
  properties: {
    params: {
      type: null
    }
  },
  data: {
    //跟据数字选颜色
    hascolor: '',
    //根据数据显示上下箭头颜色
    colorshow: '',
  }, // 私有数据，可用于模板渲染

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {

    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {

  }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {

  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },

  methods: {
    toggle(e) {
      let idx = e.currentTarget.dataset.idx;
      let order_field = '';
      switch (idx) {
      case 1:
        this.setData({
          hascolor: 1
        });
        if (this.data.colorshow == '1_2') {
          this.setData({
            colorshow: '1_1'
          });
          order_field = 'comment_num';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'asc'
          });
        } else {
          this.setData({
            colorshow: '1_2'
          });
          order_field = 'comment_num';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'desc'
          });
        }
        break;
      case 2:
        this.setData({
          hascolor: 2
        });
        if (this.data.colorshow == '2_2') {
          this.setData({
            colorshow: '2_1',
          });
          order_field = 'show_sales';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'asc'
          });
        } else {
          this.setData({
            colorshow: '2_2',
          });
          order_field = 'show_sales';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'desc'
          });
        }
        break;
      case 3:
        this.setData({
          hascolor: 3,
        });
        if (this.data.colorshow == '3_2') {
          this.setData({
            colorshow: '3_1'
          });
          order_field = 'price';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'asc'
          });
        } else {
          this.setData({
            colorshow: '3_2'
          });
          order_field = 'price';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'desc'
          });
        }
        break;
      case 5:
        this.setData({
          hascolor: 5,
        });
        if (this.data.colorshow == '5_2') {
          this.setData({
            colorshow: '5_1'
          });
          order_field = 'id';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'asc'
          });
        } else {
          this.setData({
            colorshow: '5_2'
          });
          order_field = 'id';
          this.triggerEvent('sortIn', {
            order_field: order_field,
            order_by: 'desc'
          });
        }
        break;
      }
    }
  }
});
